package com.whfc.openapi.api.face.controller;

import com.alibaba.fastjson.JSONObject;
import com.whfc.common.face.wheatSunshine.RecCallBack;
import com.whfc.emp.enums.FaceGateType;
import com.whfc.emp.param.EmpAttendSyncDataParam;
import com.whfc.openapi.api.face.service.FaceGateSyncService;
import com.whfc.openapi.api.face.util.FaceGateDataConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 麦管家人脸机回调接口
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/9/4 15:40
 */
@RestController
@RequestMapping("/open/api/faceGate")
public class FaceGateMgjController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private FaceGateSyncService faceGateSyncService;

    /***************麦管家人脸识别闸机回调**************/

    @PostMapping("imgRegCallBack")
    public String imgRegCallBack(@RequestBody String body) {
        logger.info("[人脸识别][拍照回调]:{}", body);
        JSONObject ret = new JSONObject();
        ret.put("result", 1);
        ret.put("success", true);
        return ret.toString();
    }

    @PostMapping("cardCallBack")
    public String identifyCallBack(@RequestBody String body) {
        logger.info("[人脸识别][读卡回调]:{}", body);
        JSONObject ret = new JSONObject();
        ret.put("result", 1);
        ret.put("success", true);
        return ret.toString();
    }

    @PostMapping("recCallBack")
    public String recCallBack(@RequestBody String body) {
        logger.info("[人脸识别][考勤回调]:{}", body);
        RecCallBack data = JSONObject.parseObject(body, RecCallBack.class);
        EmpAttendSyncDataParam dataParam = FaceGateDataConverter.attendDataConverter(data);
        if (dataParam != null) {
            dataParam.setPlatform(FaceGateType.WHEATSUNSHINE.getCode());
            faceGateSyncService.syncAttend(dataParam);
        }
        JSONObject ret = new JSONObject();
        ret.put("result", 1);
        ret.put("success", true);
        return ret.toString();
    }

}
